import {
  accessify,
  soExternal,
  beTraits,
} from './entry'

import {
  Trait
} from '../ast/types'

import sign from '../ast/sign'

const
  IDENT   = sign.ident,
  TRAITS  = sign.traits

export default function (s) {
  let
    start  = s.start,
    access = accessify(s.text()),
    id     = s.beId(),
    sign   = s.soRight(),
    traits = sign === TRAITS
      && beTraits(s)
      || sign && s.fail(sign)
      || null

  return new Trait(access, id, traits)
    .start(start).end((traits || id).loc.end)
}
